package com.wuye.action;

import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wuye.entity.Fangchan;
import com.wuye.service.FangchanService;
import com.wuye.service.UsersService;

@Controller
@RequestMapping("/fangchan")
public class FangchanAction {
	@Resource
	private FangchanService fangchanService;
	//增加
	@RequestMapping("/save")
	public String save(Fangchan fangchan,HttpServletRequest request){
		fangchanService.save(fangchan);
		request.setAttribute("msg", "已添加");
		return "goPage.do";
	}
	//删除
	@RequestMapping("/del")
	public String del(String str,HttpServletRequest request){
		fangchanService.del(str);
		request.setAttribute("msg", "已删除");
		return "goPage.do";
	}
	//跳转页面
	@RequestMapping("/goPage")
	public String goPage(HttpServletRequest request){
		fangchanService.goPage(request);
		return "../fc.jsp";
	}
	//更新
	@RequestMapping("/update")
		public String update(Fangchan fangchan,HttpServletRequest request){
			fangchanService.update(fangchan);
			request.setAttribute("msg", "已更新");
			return "goPage.do";
		}
	//列表
	@RequestMapping("/allList")
	public @ResponseBody Map getAllList(String page,String rows,HttpServletRequest request){
		int intPage = Integer.parseInt((page == null || page =="0") ? "1":page); 
        int number = Integer.parseInt((rows == null || rows =="0") ? "10":rows); 
        int start = (intPage-1)*number; 
        return fangchanService.getList(start,number);
	}
	//查询
	@RequestMapping("/searchList")
	public @ResponseBody Map getSearchList(Fangchan fangchan,String page,String rows,HttpServletRequest request) throws Exception{
		int intPage = Integer.parseInt((page == null || page =="0") ? "1":page); 
        int number = Integer.parseInt((rows == null || rows =="0") ? "10":rows); 
        int start = (intPage-1)*number; 
        return fangchanService.getSearchList(fangchan,start,number);
	}
	public FangchanService getFangchanService() {
		return fangchanService;
	}
	public void setFangchanService(FangchanService fangchanService) {
		this.fangchanService = fangchanService;
	}
}
